package com.gykfbxxh.imovie.bean.news;

import android.content.Context;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.app.utils.util.DateUtils;
import com.app.utils.util.view.image.CircleImageView;
import com.gykfbxxh.imovie.R;
import com.gykfbxxh.imovie.bean.film.FilmEntity;
import com.gykfbxxh.imovie.bean.film.FilmListEntity;
import com.gykfbxxh.imovie.utils.glide.ImageLoader;

import java.util.HashMap;

/**
 * 列表的左图小图UI
 * Created by xuxinghai on 2017/8/30.
 */
public class ViewLeftImg {

    public TextView tv_title;
    public ImageView iv_rightimg;
    public CircleImageView civ_usericon;
    public TextView tv_username;
    public TextView tv_time;
    public TextView tv_commentsum;
    public CheckBox cb_checkbox;


    private int width = 324;
    private int height = 232;

    public ViewLeftImg(View convertView,Context context) {
        initView(convertView,context);
    }


    /**
     * 初始化控件
     * @param convertView
     */
    public void initView(View convertView,Context context) {
        cb_checkbox = (CheckBox) convertView.findViewById(R.id.cb_checkbox);
        tv_title = (TextView) convertView.findViewById(R.id.tv_title);
        iv_rightimg = (ImageView) convertView.findViewById(R.id.iv_rightimg);
        civ_usericon = (CircleImageView) convertView.findViewById(R.id.civ_usericon);
        tv_username = (TextView) convertView.findViewById(R.id.tv_username);
        tv_time = (TextView) convertView.findViewById(R.id.tv_time);
        tv_commentsum = (TextView) convertView.findViewById(R.id.tv_commentsum);
        convertView.setTag(this);
//        ((MyCollectActivity)context).setOnCollectEditListener(new CollectEditListener() {
//            @Override
//            public void showAllCheckBox() {
//                cb_checkbox.setVisibility(View.VISIBLE);
//            }
//
//            @Override
//            public void hideAllCheckBox() {
//                cb_checkbox.setVisibility(View.GONE);
//            }
//        });
    }

    /**
     * 加载数据
     * @param listBean
     */
    public void loadData(Context context,FilmListEntity listBean, boolean isCheckVisible, final HashMap<Integer, FilmEntity> isSelected , final int position  ,boolean isAllCheck){
        final FilmEntity filmEntity = listBean.getFObject();
        if(isCheckVisible) {
            cb_checkbox.setVisibility(View.VISIBLE);
        }else {
            cb_checkbox.setVisibility(View.GONE);
        }

        if(isAllCheck) {
            cb_checkbox.setChecked(true);
            isSelected.put(position,filmEntity);
        }else {
            cb_checkbox.setChecked(false);
            try {
                isSelected.remove(position);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        cb_checkbox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(cb_checkbox.isChecked()) {
                    isSelected.put(position,filmEntity);
                }else {
                    try {
                        isSelected.remove(position);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        });

        tv_username.setText(filmEntity.getFDirector());
        tv_title.setText(filmEntity.getFKeyword());
        tv_time.setText(DateUtils.getStrTime_mdhm(DateUtils.getTime(filmEntity.getFIntime())));
        ImageLoader.getInstance().listLoadImage2Cache(context,iv_rightimg,listBean.getFObject().getFPhotow());
        ImageLoader.getInstance().loadImage2Cache(context,civ_usericon,listBean.getFObject().getFPhotos());
        tv_commentsum.setText(listBean.getFObject().getFCommentct()+"");
    }

    /**
     * 加载数据
     * @param listBean
     */
    public void loadAboutData(Context context,FilmEntity listBean){
//        tv_title.setText(listBean.getFName());
        ImageLoader.getInstance().listLoadImage2Cache(context,iv_rightimg,listBean.getFPhotow());
        ImageLoader.getInstance().loadImage2Cache(context,civ_usericon,listBean.getFPhotos());
//        tv_username.setText(listBean.getFName());
        tv_commentsum.setText(listBean.getFCommentct()+"");
    }

}
